import 'package:flutter/material.dart';

class SliverBarDemo extends StatelessWidget {
  const SliverBarDemo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // appBar: AppBar(
      //   title: Text('demo'),
      // ),
      body: CustomScrollView(
        slivers: [
          SliverAppBar(
            // title: Text('sliver appbar'),
            // floating: true,
            pinned: true, // 固定
            // snap: true, // 稍微下拉就出来
            expandedHeight: 200,
            stretch: true, //向下拉伸时的效果
            flexibleSpace: FlexibleSpaceBar(
              background: FlutterLogo(),
              title: Text('我是底部的appBAr'),
              stretchModes: [
                StretchMode.blurBackground,
                StretchMode.fadeTitle,
                StretchMode.zoomBackground
              ],
            ),
          ),
          SliverToBoxAdapter(
            child: Placeholder(),
          ),
          SliverPersistentHeader(
            delegate: _MyDelete(),
            pinned: true,
          ),
          SliverOpacity(
            opacity: 0.4,
            sliver: SliverList(
                delegate: SliverChildListDelegate([
              FlutterLogo(
                size: 200,
              ),
              FlutterLogo(),
              // FlutterLogo(
              //   size: 300,
              // ),
              // FlutterLogo(
              //   size: 100,
              // ),
              // FlutterLogo(
              //   size: 300,
              // ),
            ])),
          ),
          SliverFillRemaining(
            child: Container(
              color: Colors.red,
              child: Center(
                child: Text('fas'),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

class _MyDelete extends SliverPersistentHeaderDelegate {
  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    // TODO: implement build
    return Container(
      height: 50,
      color: Colors.green,
      child: Text('fas'),
    );
  }

  @override
  // TODO: implement maxExtent
  double get maxExtent => 50;

  @override
  // TODO: implement minExtent
  double get minExtent => 50;

  @override
  bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
    // TODO: implement shouldRebuild
    return true;
  }
}
